﻿using System;
using System.Collections.Generic;

namespace $DomainProjectName$.Repositories
{
    /// <summary>
    /// Base interface for all repositories
    /// </summary>
    /// <typeparam name="T">Domain type</typeparam>
    public interface IRepository<T>
    {
        /// <summary>
        /// Gets the entity from the persistance store, or return null if it doesn't exist.
        /// </summary>
        /// <param name="id">Entity's id</param>
        /// <returns>Either the entity that matches the id, or a null</returns>
        T Get(object id);

        /// <summary>
        /// Loads an entity from the persistance store. Will throw an exception if there 
        /// isn't an entity that matches the id.
        /// </summary>
        /// <param name="id">Entity's id</param>
        /// <returns>Entity that matches the id</returns>
        T Load(object id);

        /// <summary>
        /// Deletes an entity
        /// </summary>
        /// <param name="entity">Entity to delete</param>
        void Delete(T entity);

        /// <summary>
        /// Deletes all entities
        /// </summary>
        void DeleteAll();

        /// <summary>
        /// Saves an entity
        /// </summary>
        /// <param name="entity">Entity to save</param>
        /// <returns>The saved entity</returns>
        void Save(T entity);

        /// <summary>
        /// Saves or updates an entity, based on its unsaved-value
        /// </summary>
        /// <param name="entity">Entity to update or update</param>
        /// <returns>The saved or updated entity</returns>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// Updates an entity
        /// </summary>
        /// <param name="entity">Entity to update</param>
        void Update(T entity);

        /// <summary>
        /// Loads all the entities
        /// </summary>
        /// <returns>Collection of entities</returns>
        ICollection<T> FindAll();

        /// <summary>
        /// Loads all the entities, and allow paging
        /// </summary>
        /// <param name="firstResult">The first result to load</param>
        /// <param name="numberOfResults">Total number of results to load</param>
        /// <returns>Collection of entities</returns>
        ICollection<T> FindAll(int firstResult, int numberOfResults);
    }
}
